<?php

class User_LoginController extends Zend_Controller_Action{

	protected $_requestUri = null;
	
	public function init(){
		if($this->getRequest()){
			$this->_requestUri = $this->_getParam('nextPage'); 
		}
	}
	public function indexAction(){
		
		
		
		$form = new Custom_Form_Login(
			array(
				'action'	=>	'/user/login',
				'method'	=>	'post'
			)
		);
		
		$form->addElement('hidden', 'nextPage', array(
				'decorators'	=>	$form->hiddenDecorators,
				'value'	=>	$this->_requestUri
		));
		
		if($this->getRequest()->isPost()){
	
			//$this->view->message = $form->processAjax($_POST);
			
			$user = new Doctrine_Model_Users();
			$user->setPassword($this->_getParam('password'));

			$adapter = new Auth_Adapter($this->_getParam('username'),$user->password);
			$result = Zend_Auth::getInstance()->authenticate($adapter);
			
			if($result){
				if($this->_getParam('nextPage'))
					$this->_helper->redirector->gotoUrl($this->_getParam('nextPage'));
				else{
//					display login successful
				}
			}else{
//				display login unseccessful
			}
		}
		$this->view->form = $form;
		$this->view->nextPage = $this->_requestUri;
	}	
}